package cars

import (
	"parking-lot-go-dingding/model"
	"time"
)

type CarsOutStruct struct {
	Id             int       `gorm:"type:int(11) auto_increment; NOT NULL; primary_key"`
	ParkCode       string    `gorm:"type:varchar(255); COMMENT:'停车场码'"`
	ParkName       string    `gorm:"type:varchar(255); COMMENT:'停车场名称'"`
	CarNumber      string    `gorm:"type:varchar(255); COMMENT:'车牌号'"`
	InTime         time.Time `gorm:"type:datetime; COMMENT:'入场时间'"`
	InPhoto        string    `gorm:"type:varchar(255); COMMENT:'入场图片'"`
	OutTime        time.Time `gorm:"type:datetime; COMMENT:'出场时间'"`
	OutPhoto       string    `gorm:"type:varchar(255); COMMENT:'出场图片'"`
	RegionCode     string    `gorm:"type:varchar(255); COMMENT:'出场区域编号'"`
	RegionName     string    `gorm:"type:varchar(255); COMMENT:'出场区域名称'"`
	ParkTime       int       `gorm:"type:int(11); COMMENT:'停车时长,单位：分钟'"`
	ParkAmt        int       `gorm:"type:int(11); COMMENT:'停车费用，单位：分'"`
	CouponAmt      int       `gorm:"type:int(11); COMMENT:'停车优惠，单位：分'"`
	ChargeAmt      int       `gorm:"type:int(11); COMMENT:'实收金额，单位：分'"`
	SerialNo       string    `gorm:"type:varchar(255); COMMENT:'出场流水号'"`
	Otype          int       `gorm:"type:int(11); COMMENT:'结算方式（企业1，个人2，混合3）'"`
	AmountPlatform int       `gorm:"type:int(11); COMMENT:'平台扣款，单位：分'"`
	AmountUser     int       `gorm:"type:int(11); COMMENT:'个人结算金额，单位：分'"`
	CreatedAt      time.Time `gorm:"type:datetime"`
	UpdatedAt      time.Time `gorm:"type:datetime"`
	CarNoColor     int       `gorm:"type:tinyint(1); COMMENT:'车牌颜色'"`
	MuchId         string    `gorm:"type:varchar(255)"`
	OrderNo        string    `gorm:"type:varchar(255)"`
	OrderType      int       `gorm:"type:tinyint(1); COMMENT:'订单类型'"`
	CarType        int       `gorm:"type:tinyint(1); COMMENT:'车辆类型'"`
	PushStatus     int       `gorm:"type:tinyint(1); COMMENT:'推送状态'"`
	PushErrNum     int       `gorm:"type:tinyint(1); COMMENT:'失败次数'"`
	PushTime       int       `gorm:"type:tinyint(1); COMMENT:'下次推送时间'"`
}

func (c *CarsOutStruct) TableName() string {
	return "cars_out"
}

func (c *CarsOutStruct) List(where map[string]interface{}) ([]CarsOutStruct, error) {

	var list []CarsOutStruct

	//查询条件
	db := model.Db

	if err := db.
		Table(c.TableName()).
		Where(where).
		Order("id desc").
		Scan(&list).Error; err != nil {
		return nil, err
	}

	return list, nil
}

func (c *CarsOutStruct) Count(where map[string]interface{}) (int64, error) {
	var count int64

	if err := model.Db.Table(c.TableName()).Where(where).Count(&count).Error; err != nil {
		return 0, err
	}
	return count, nil
}
